/*
 * XProxyAction.java, created on Nov 2, 2005
 * 
 * Copyright (c) 2005 - 2007 Devon Carew
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package org.xfc.components;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.Action;

/**
 *
 *
 * @author Devon Carew
 */
public class XProxyAction
	extends XDefaultAction
{
	protected Action	proxyAction;
	
	private PropertyChangeListener enabledListener = new PropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			setEnabled(proxyAction == null ? false : proxyAction.isEnabled());
		}
	};

	/**
	 * 
	 */
	public XProxyAction()
	{
		setEnabled(false);
	}

	/**
	 * @param command
	 */
	public XProxyAction(String command)
	{
		super(command);
		
		setEnabled(false);
	}
	
	public void actionPerformed(ActionEvent event)
	{
		if (proxyAction != null)
			proxyAction.actionPerformed(event);
	}
	
	/**
	 * @param action
	 */
	public void setActionProxy(Action action)
	{
		if (proxyAction != null)
			proxyAction.removePropertyChangeListener(enabledListener);
		
		proxyAction = action;
		
		if (proxyAction != null)
			proxyAction.addPropertyChangeListener(enabledListener);
		
		setEnabled(proxyAction == null ? false : proxyAction.isEnabled());
	}
	
}
